package my.diplom.dao.impl;

import my.diplom.dao.IStatDAO;
import my.diplom.entity.Stat;
import my.diplom.entity.Resource;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.orm.hibernate3.HibernateTemplate;

/**
 * Created by IntelliJ IDEA.
 * User: gb
 * Date: 14.07.2009
 * Time: 16:52:22
 * To change this template use File | Settings | File Templates.
 */
public class StatDAOImpl implements IStatDAO {

    private static final Logger log = Logger.getLogger(StatDAOImpl.class);

    private HibernateTemplate template;

    public void setTemplate(HibernateTemplate template) {
        this.template = template;
    }

    public void create(Stat stat) {
        log.debug("create stat");
        template.save(stat);
    }

    public void update(Stat stat) {
        log.debug("update stat");
        template.update(stat);
    }

    public Stat getById(Long statId) {
        log.debug("get stat by id = " + statId);
        return (Stat)template.get(Stat.class, statId);
    }

    public List<Stat> getAll() {
        log.debug("get all stats");
        //noinspection JpaQlInspection
        return template.find("from Stat order by date");
    }

    public void delete(Stat stat) {
        log.debug("delete stat");
        template.delete(stat);
    }
}
